<?php
/**
 * Default Widget Manager Template
 *
 * @package OWL
 * @subpackage Default Template
 * @author KeiMOon
 * @since 1.0
 */

if (!defined("DEFAULT_SITE_LOGO")) {
    define("DEFAULT_SITE_LOGO", "images/logo/owl-logo-light-96.png");
}

class Template_System_Options extends Owl_Master_Template {
    protected function init() {
        $user = Owl_User::get_instance();
        if (!$user->is_logged_in()) {
            Owl_Functions::go_to_template("login");
        }
        assign("title", get_option("site_name") . " - " . __("System options"));
        assign("page-title", __("System options"));
        enqueue_style('default-setting,default-icon,default-ajax');
        enqueue_script('default-system-options');
    }

    protected function main_content() {
?>
<div id="setting-navigation">
    <?php Owl_Default_Content::setting_navigation(); ?>
    <div style="clear:both;"></div>
</div>
<div id="setting-page-header" class="has-icon icon-system-options-48">
    <div id="setting-page-title">
        <?php put("page-title"); ?>
    </div>
</div>
<div id="setting-main-content">
    <div style="margin-top:10px;">
        <form action="<?php Owl_Link::ajax_url(); ?>system-ajax.php" method="POST" id="system-form" enctype="multipart/form-data">
            <?php
            Owl_Form::print_hidden(array(
                "name" => "action",
                "value" => "system_update"
            ));
            ?>
            <table class="form-table" border="0" cellpadding="0" cellspacing="0">
                <tbody>
                    <tr>
                        <td colspan="2">
                            <h3><?php echo __("Display"); ?></h3>
                        </td>
                    </tr>
                    <tr>
                        <th width="50%">
                            <?php
                            Owl_Form::print_label(array(
                                "value" => __("Site name"),
                                "for" => "system_site_name"
                            ));
                            ?>
                        </th>
                        <td width="50%">
                            <?php
                            Owl_Form::print_textbox(array(
                                "name" => "site_name",
                                "value" => Owl_Format::esc_html(get_option("site_name")),
                                "id" => "system_site_name",
                                "description" => __("Name of your web site, should be as short as possible")
                            ));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?php
                            Owl_Form::print_label(array(
                                "value" => __("Site description"),
                                "for" => "system_site_description"
                            ));
                            ?>
                        </th>
                        <td>
                            <?php
                            Owl_Form::print_textbox(array(
                                "name" => "site_description",
                                "value" => Owl_Format::esc_html(get_option("site_description")),
                                "id" => "system_site_description",
                                "description" => __("Description of your web site, should be as short as possible")
                            ));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?php
                            Owl_Form::print_label(array(
                                "value" => __("Site logo"),
                                "for" => "system_site_logo"
                            ));
                            ?>
                        </th>
                        <td>
                            <?php
                            Owl_Form::print_file_image(array(
                                "name" => "site_logo",
                                "value" => Owl_Link::site_url(false) . get_option("site_logo", DEFAULT_SITE_LOGO),
                                "id" => "system_site_logo",
                                "description" => __("Your website logo, should be 96px width"),
                                "width" => 96
                            ));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?php
                            Owl_Form::print_label(array(
                                "value" => __("Use default logo"),
                                "for" => "system_use_default_logo"
                            ));
                            ?>
                        </th>
                        <td>
                            <?php
                            Owl_Form::print_check_box(array(
                                "name" => "use_default_logo",
                                "id" => "system_use_default_logo"
                            ));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?php
                            Owl_Form::print_label(array(
                                "value" => __("Content per page"),
                                "for" => "system_content_per_page"
                            ));
                            ?>
                        </th>
                        <td>
                            <?php
                            Owl_Form::print_combo_box(array(
                                "name" => "content_per_page",
                                "id" => "system_content_per_page",
                                "options" => array(5 => 5, 10 => 10, 15 => 15, 20 => 20),
                                "value" => get_option("content_per_page", 10)
                            ));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?php
                            Owl_Form::print_label(array(
                                "value" => __("Max pages display"),
                                "for" => "system_max_pages_display"
                            ));
                            ?>
                        </th>
                        <td>
                            <?php
                            Owl_Form::print_combo_box(array(
                                "name" => "max_pages_display",
                                "id" => "system_max_pages_display",
                                "options" => array(5 => 5, 10 => 10, 15 => 15, 20 => 20),
                                "value" => get_option("max_pages_display", 5)
                            ));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?php
                            Owl_Form::print_label(array(
                                "value" => __("Product sort type"),
                                "for" => "system_product_sort"
                            ));
                            ?>
                        </th>
                        <td>
                            <?php
                            Owl_Form::print_combo_box(array(
                                "name" => "product_sort",
                                "id" => "system_product_sort",
                                "options" => array(0 => __("Ascending"), 1 => __("Descending")),
                                "value" => get_option("product_sort", 1),
                                'description' => __('The order to sort products by year')
                            ));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <h3><?php echo __("System"); ?></h3>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?php
                            Owl_Form::print_label(array(
                                "value" => __("Language"),
                                "for" => "system_language"
                            ));
                            ?>
                        </th>
                        <td>
                            <?php
                            $available_languages = Owl_Functions::get_available_languages();
                            Owl_Form::print_combo_box(array(
                                "name" => "language",
                                "id" => "system_language",
                                "options" => $available_languages,
                                "value" => get_option("language", "en")
                            ));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?php
                            Owl_Form::print_label(array(
                                "value" => __("GMT Offset"),
                                "for" => "system_gmt_offset"
                            ));
                            ?>
                        </th>
                        <td>
                            <?php
                            $gmt_list = Owl_Functions::get_gmt_offset_list();
                            Owl_Form::print_combo_box(array(
                                "name" => "gmt_offset",
                                "id" => "system_gmt_offset",
                                "options" => $gmt_list,
                                "value" => get_option("gmt_offset", DEFAULT_GMT_OFFSET)
                            ));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?php
                            Owl_Form::print_label(array(
                                "value" => __("Lock widget"),
                                "for" => "system_widget_lock"
                            ));
                            ?>
                        </th>
                        <td>
                            <?php
                            Owl_Form::print_check_box(array(
                                "name" => "widget_lock",
                                "id" => "system_widget_lock",
                                "value" => (get_option("widget_lock")) ? "on" : "",
                                "description" => __("When widgets are locked, you can only config them in the widget manager page")
                            ));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?php
                            Owl_Form::print_label(array(
                                "value" => __("Effect"),
                                "for" => "system_site_effect"
                            ));
                            ?>
                        </th>
                        <td>
                            <?php
                            Owl_Form::print_check_box(array(
                                "name" => "site_effect",
                                "id" => "system_site_effect",
                                "value" => (get_option("site_effect")) ? "on" : "",
                                "description" => __("Javascript effect of your site")
                            ));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?php
                            Owl_Form::print_label(array(
                                "value" => __("Default home page"),
                                "for" => "system_home_template"
                            ));
                            ?>
                        </th>
                        <td>
                            <?php
                            Owl_Form::print_combo_box(array(
                                "name" => "home_template",
                                "id" => "system_home_template",
                                "options" => array(
                                    'note' => __('Note'),
                                    'info' => __('Personal info')
                                ),
                                "value" => get_option("home_template", 'note')
                            ));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <?php Owl_Default_Content::print_ajax_feedback(false); ?>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" class="form-button-pane">
                            <img src=" <?php Owl_Link::image_url(); ?>default/ajax-load.gif" class="ajax-load" alt="Ajax load" />
                            <?php
                            Owl_Form::print_button(array(
                                "name" => "submitForm",
                                "value" => __("Save"),
                                "class" => "form-button options-update"
                            ));
                            Owl_Form::print_button(array(
                                "type" => "reset",
                                "name" => "cancel",
                                "value" => __("Cancel")
                            ));
                            ?>
                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </div>
</div>

<?php
    }
}